package ch.cern

class PointService {

  def getStats(List<Point> points) {
    def stats = [:]
    stats.count = points.size()

    //group points by tags
    def _tags = [:]
    points.each {p->p.tags.each {t->
      if (_tags[t.tag] == null)
        _tags[t.tag] = []
      _tags[t.tag].add(p)
    }}

    stats.tags = _tags
    stats.fromDate = points.collect{it.createdOn}.min()
    stats.toDate = points.collect{it.createdOn}.max()
    return stats
  }

}
